package com.rabbit2020.config;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonAlias;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 作者: LCG
 * 日期: 2020/2/28 00:00
 * 描述: 防止消息 在从交换机发送到队列的时候失败
 */
@Component
public class RabbitTemplateReturn implements RabbitTemplate.ReturnCallback {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init(){
        rabbitTemplate.setReturnCallback(this);
    }

    @Override
    public void returnedMessage(Message message, int i, String s, String s1, String s2) {
        System.out.println("=====message=====>"+ JSON.toJSONString(message)+"-i--"+i+"====s===="+s+"====s1=="+s1+"===s2==="+s2);
    }

}
